<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <title>聊天界面</title>
    

    <link href="${basePath}/css/global.css" rel="stylesheet">
    <link href="${basePath}/css/styles.css" rel="stylesheet">
    <script type="text/javascript" src="${basePath}/assets/js/jquery.min.js"></script>
    <script type="text/javascript" src="${basePath}/assets/js/chat.js"></script>
</head>
<body class="chat-bg">
<header class="header-title"><span id="title"></span></header>
<label></label>
<section class="chat-box">
    <span class="chat-trip">此刻对方忙碌，请留言</span>
    <div class="bubbleDiv"></div>
</section>
<footer class="chat-edit clearfix">
    <p class="chat-info" placeholder="想咨询他什么内容..." contenteditable="true"></p>
    <span class="uploadImg fl" style="background: url('${basePath}/assets/images/icon-m.png') no-repeat;"><input type="textarea" name="uploadfile" class="uploadfile"></span>
    <button class="send-btn fr">发送</button>
</footer>


<script>
	//$("#title").val(parent.taskTitle);
	//$("#taskId").val(parent.taskId);
	
	var parentId;
	
	function fuzhi(messId){
			//alert(messId);
			parentId = messId;
			$('.chat-info').focus();
	}
	
	
    $(document).ready(function(){
		
		var data = ${taskMessageVos};
		//alert(data);
		var result;
		
		$('#title').html('任务:'+parent.taskTitle+'  创建者:'+parent.createUname+'  时间:'+parent.createTime);
		//$('#title').html(parent.taskTitle+'  '+parent.createUname+'  '+parent.createTime);
		var mess;
		$.each(data,function(index,data){
			//alert(data.message_content);
			if(data.message_cla=='rightBubble'){
				mess = data.message_content;
			}else{
				mess = data.message_content+"</br><a href='javascript:void(0)' onclick='fuzhi("+data.task_message_id+")'><span>>>回复</span></a>";
			}
			
			chat(data.message_cla,"${basePath}/assets/images/head_portrait.png",mess,1);
        });  
		
		

        $(".send-btn").click(function(){
            //右侧 自己发 调用，只需填一个参数"rightBubble"
            chat("rightBubble");
            //alert($('.chat-info').html());
            
            var taskId = parent.taskId;
            var messageContent = $('.chat-info').html();
            var TaskUid = parent.createUid;
            
           

            $.ajax({
                type: "post",
                data: { "taskId": taskId, "messageContent":messageContent,"TaskUid": TaskUid,"parentId":parentId}, 
                url: "${basePath}/taskMessage/addMessage",
                dataType: "json",
                beforeSend:function () {
                    
                },
                success: function (data) {
                    if (data.status == "0") {
                    }else {
                    }
                },
                error: function(xhr, textStatus, errorThrown) {
                    
                }
            });
            
            
            
            
            //清空输入框
            $('.chat-info').html('');

        })
    })
</script>
</body>
</html>